package cn.tth.test.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.*;

public class ThreadService {

    public static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(4);

    public static final ConcurrentHashMap MAP = new ConcurrentHashMap();

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        List<Future> futureList = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            Future<Object> future = EXECUTOR_SERVICE.submit(new Callable<>() {
                @Override
                public Object call() throws Exception {
                    MAP.put(UUID.randomUUID().toString(),"23");
                    Thread.sleep(100);
                    return null;
                }
            });
            futureList.add(future);
        }
        for (Future future : futureList) {
            future.get();
        }
        System.out.println(MAP.size());
    }
}
